package com.lzit.smart_canteen.service;

import com.lzit.smart_canteen.domain.CartItem;
import com.lzit.smart_canteen.domain.Order;
import com.lzit.smart_canteen.repository.OrderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderService {
    @Autowired
    private OrderRepository orderRepository;


    //创建新订单
    public void addOrder(Order order) {
        orderRepository.save(order);
    }

    //通过订单id查找订单
    public Order findOrderByOid(String oid){
        return orderRepository.findOrderByOid(oid);
    }

    //通过用户id查找订单
    public List<Order> findOrdersByUid(Integer uid) {
        return orderRepository.findOrdersByUid(uid);
    }

    //通过用户id和订单状态查找订单
    public List<Order> findOrdersByUidAndStatus(Integer uid,String status) {
        return orderRepository.findOrdersByUidAndStatus(uid,status);
    }

    //通过订单id删除订单
    public void deleteOrderByOid(String oid){
        orderRepository.deleteOrderByOid(oid);
    }

    //更新订单状态
    public void updateStatusByOid(String oid,String status){
        orderRepository.updateStatusByOid(oid,status);
    }
}
